<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveSupport::PerThreadRegistry</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveSupport::PerThreadRegistry 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/activesupport/lib/active_support/per_thread_registry_rb.html">activesupport/lib/active_support/per_thread_registry.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>This module is used to encapsulate access to thread local variables.</p>

<p>Instead of polluting the thread locals namespace:</p>

<pre>Thread.current[:connection_handler]</pre>

<p>you define a class that extends this module:</p>

<pre class="ruby"><span class="ruby-keyword">module</span> <span class="ruby-constant">ActiveRecord</span>
  <span class="ruby-keyword">class</span> <span class="ruby-constant">RuntimeRegistry</span>
    <span class="ruby-identifier">extend</span> <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">PerThreadRegistry</span>

    <span class="ruby-identifier">attr_accessor</span> :<span class="ruby-identifier">connection_handler</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>and invoke the declared instance accessors as class methods. So</p>

<pre>ActiveRecord::RuntimeRegistry.connection_handler = connection_handler</pre>

<p>sets a connection handler local to the current thread, and</p>

<pre>ActiveRecord::RuntimeRegistry.connection_handler</pre>

<p>returns a connection handler local to the current thread.</p>

<p>This feature is accomplished by instantiating the class and storing the
instance as a thread local keyed by the class name. In the example above a
key “ActiveRecord::RuntimeRegistry” is stored in
<code>Thread.current</code>. The class methods proxy to said thread local
instance.</p>

<p>If the class has an initializer, it must accept no arguments.</p>

    </div>
  


  


  
  


  


  

  



  

    

    

    


    


    <!-- Methods -->
              </div>

    </div>
  </body>
</html>    